unit uniRelPedidoDet;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, QuickRpt, QRCtrls, jpeg, ExtCtrls, ADODB;

type
  TfrmRelPedidoDet = class(TForm)
    qrpRel: TQuickRep;
    QRBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    qrlPeriodo: TQRLabel;
    qrImgCliente: TQRImage;
    qrbDetalhe: TQRBand;
    qrlLabel99: TQRLabel;
    qrlProduto: TQRLabel;
    QRBand3: TQRBand;
    QRBand2: TQRBand;
    QRLabel14: TQRLabel;
    QRSysData2: TQRSysData;
    QRSysData1: TQRSysData;
    qrlUsuario: TQRDBText;
    DS_Rel: TDataSource;
    qrlCdPedido: TQRLabel;
    QRLabel4: TQRLabel;
    qrlRazaoSocial: TQRLabel;
    QRLabel6: TQRLabel;
    qrlMarca: TQRLabel;
    QRLabel7: TQRLabel;
    qrlPrazo: TQRLabel;
    qrlCondicaoPagamento: TQRLabel;
    QRLabel10: TQRLabel;
    QRLabel11: TQRLabel;
    qrlRepresentante: TQRLabel;
    QRLabel8: TQRLabel;
    qrlDataPedido: TQRLabel;
    QRLabel3: TQRLabel;
    QRLabel5: TQRLabel;
    QRLabel9: TQRLabel;
    QRLabel12: TQRLabel;
    qrlMaterial1: TQRLabel;
    qrlMaterial2: TQRLabel;
    qrlMaterial3: TQRLabel;
    qrlMaterial4: TQRLabel;
    qrlMaterial5: TQRLabel;
    qrlCorSilk1: TQRLabel;
    qrlCorSilk2: TQRLabel;
    qrlCorSilk3: TQRLabel;
    qrlCorSilk4: TQRLabel;
    qrlCorSilk5: TQRLabel;
    QRLabel19: TQRLabel;
    QRLabel20: TQRLabel;
    QRLabel21: TQRLabel;
    QRLabel22: TQRLabel;
    QRLabel23: TQRLabel;
    QRLabel13: TQRLabel;
    qrlRelevoSN: TQRLabel;
    QRLabel15: TQRLabel;
    qrlCorEspumex: TQRLabel;
    QRLabel16: TQRLabel;
    qrlQuantidade: TQRLabel;
    QRLabel17: TQRLabel;
    qrlValorUnitario: TQRLabel;
    QRLabel18: TQRLabel;
    qrlObs: TQRLabel;
    QR_Rel: TADOQuery;
    QRLabel24: TQRLabel;
    qrlQtdTotal: TQRLabel;
    QRLabel26: TQRLabel;
    qrlValorTotal: TQRLabel;
    QR_Temp: TADOQuery;
    QR_RelCD_PEDIDO: TWideStringField;
    QR_RelDATA: TDateTimeField;
    QR_RelRAZAO: TWideStringField;
    QR_RelDS_MARCA: TWideStringField;
    QR_RelNOME: TWideStringField;
    QR_RelDS_CONDICAO_PAGAMENTO: TWideStringField;
    QR_RelPRAZO: TIntegerField;
    QR_RelQTD_TOTAL: TIntegerField;
    QR_RelVALOR_TOTAL: TFloatField;
    QR_RelDS_PRODUTO: TWideStringField;
    QR_RelCD_PRODUTO_PEDIDO: TAutoIncField;
    QR_RelCD_MATERIAL1: TIntegerField;
    QR_RelCD_MATERIAL2: TIntegerField;
    QR_RelCD_MATERIAL3: TIntegerField;
    QR_RelCD_MATERIAL4: TIntegerField;
    QR_RelCD_MATERIAL5: TIntegerField;
    QR_RelCOR_SILK1: TWideStringField;
    QR_RelCOR_SILK2: TWideStringField;
    QR_RelCOR_SILK3: TWideStringField;
    QR_RelCOR_SILK4: TWideStringField;
    QR_RelCOR_SILK5: TWideStringField;
    QR_RelSN_RELEVO: TBooleanField;
    QR_RelCD_COR_ESPUMEX: TIntegerField;
    QR_RelQUANTIDADE: TIntegerField;
    QR_RelVALOR_UNITARIO: TFloatField;
    QRLabel25: TQRLabel;
    QR_RelOBS: TMemoField;
    procedure QRBand1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure qrbDetalheBeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure qrpRelBeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
  private
     function f_getMaterial(parCdMaterial:String):String;
     function f_getCorEspumex(parCdCorEspumex:String):String;
  public
    gCdPedido:String;
  end;

var
  frmRelPedidoDet: TfrmRelPedidoDet;

implementation

uses uniFuncBD, UniFuncoes;

{$R *.dfm}

function TfrmRelPedidoDet.f_getCorEspumex(parCdCorEspumex: String): String;
var sSQL:String;
begin
  sSQL := ' SELECT DS_COR_ESPUMEX FROM TB_COR_ESPUMEX '+
          ' WHERE CD_COR_ESPUMEX = '+parCdCorEspumex;
  QR_Temp.Close;
  QR_Temp.SQL.Text := sSQL;
  QR_Temp.Open;

  if QR_Temp.RecordCount > 0 then
    Result := QR_Temp.FieldByName('DS_COR_ESPUMEX').AsString
  else
    Result := '';

end;

function TfrmRelPedidoDet.f_getMaterial(parCdMaterial: String): String;
var sSQL:String;
begin
  sSQL := ' SELECT DESCRICAO FROM TB_MATERIAL '+
          ' WHERE CD_MATERIAL = '+parCdMaterial;
  QR_Temp.Close;
  QR_Temp.SQL.Text := sSQL;
  QR_Temp.Open;

  if QR_Temp.RecordCount > 0 then
    Result := QR_Temp.FieldByName('DESCRICAO').AsString
  else
    Result := '';
end;

procedure TfrmRelPedidoDet.QRBand1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  qrlCdPedido.Caption := QR_Rel.fieldbyname('CD_PEDIDO').AsString;
  qrlDataPedido.Caption := QR_Rel.fieldbyname('DATA').AsString;
  qrlRazaoSocial.Caption := QR_Rel.fieldbyname('RAZAO').AsString;
  qrlMarca.Caption := QR_Rel.fieldbyname('DS_MARCA').AsString;
  qrlRepresentante.Caption := QR_Rel.fieldbyname('NOME').AsString;
  qrlCondicaoPagamento.Caption := QR_Rel.fieldbyname('DS_CONDICAO_PAGAMENTO').AsString;
  qrlPrazo.Caption := QR_Rel.fieldbyname('PRAZO').AsString;
  qrlQtdTotal.Caption := QR_Rel.fieldbyname('QTD_TOTAL').AsString;
  qrlValorTotal.Caption := formatarValor(QR_Rel.fieldbyname('VALOR_TOTAL').AsString);
end;

procedure TfrmRelPedidoDet.qrbDetalheBeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  qrlProduto.Caption := QR_Rel.fieldbyname('DS_PRODUTO').AsString;
  //Setar os dados do produto_pedido deste produto informado
  if QR_Rel.fieldbyname('CD_MATERIAL1').AsString <> '' then
    qrlMaterial1.Caption := f_getMaterial(QR_Rel.fieldbyname('CD_MATERIAL1').AsString)
  else
    qrlMaterial1.Caption := '';

  if QR_Rel.fieldbyname('CD_MATERIAL2').AsString <> '' then
    qrlMaterial2.Caption := f_getMaterial(QR_Rel.fieldbyname('CD_MATERIAL2').AsString)
  else
    qrlMaterial2.Caption := '';

  if QR_Rel.fieldbyname('CD_MATERIAL3').AsString <> '' then
    qrlMaterial3.Caption := f_getMaterial(QR_Rel.fieldbyname('CD_MATERIAL3').AsString)
  else
    qrlMaterial3.Caption := '';

  if QR_Rel.fieldbyname('CD_MATERIAL4').AsString <> '' then
    qrlMaterial4.Caption := f_getMaterial(QR_Rel.fieldbyname('CD_MATERIAL4').AsString)
  else
    qrlMaterial4.Caption := '';

  if QR_Rel.fieldbyname('CD_MATERIAL5').AsString <> '' then
    qrlMaterial5.Caption := f_getMaterial(QR_Rel.fieldbyname('CD_MATERIAL5').AsString)
  else
    qrlMaterial5.Caption := '';

  qrlCorSilk1.Caption := QR_Rel.fieldbyname('COR_SILK1').AsString;
  qrlCorSilk2.Caption := QR_Rel.fieldbyname('COR_SILK2').AsString;
  qrlCorSilk3.Caption := QR_Rel.fieldbyname('COR_SILK3').AsString;
  qrlCorSilk4.Caption := QR_Rel.fieldbyname('COR_SILK4').AsString;
  qrlCorSilk5.Caption := QR_Rel.fieldbyname('COR_SILK5').AsString;

  if QR_Rel.fieldbyname('SN_RELEVO').AsBoolean then
  begin
    qrlRelevoSN.Caption := 'S';
    qrlCorEspumex.Caption := f_getCorEspumex(QR_Rel.fieldbyname('CD_COR_ESPUMEX').AsString);
  end
  else
  begin
    qrlRelevoSN.Caption := 'N';
    qrlCorEspumex.Caption := '';
  end;

  qrlQuantidade.Caption := QR_Rel.fieldbyname('QUANTIDADE').AsString;
  qrlValorUnitario.Caption := formatarValor(QR_Rel.fieldbyname('VALOR_UNITARIO').AsString);
  qrlObs.Caption := QR_Rel.fieldbyname('OBS').AsString; 
end;

procedure TfrmRelPedidoDet.qrpRelBeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
  QR_Rel.Close;
  QR_Rel.Parameters.ParamByName('pCdPedido').Value := gCdPedido;
  QR_Rel.Open;
end;

end.




